package com.roadmap.util.chart;

import java.awt.Color;
import java.awt.Font;

import org.apache.log4j.Logger;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.plot.Plot;
import org.jfree.chart.title.LegendTitle;
import org.jfree.chart.title.TextTitle;

import com.roadmap.common.RdcLogger;

public abstract class DataChart implements IDataChart {
	private final static Logger logger = RdcLogger.getLogger(DataChart.class);
	protected final static Font _titleFont = new Font("黑体", Font.PLAIN, 12);
	protected final static Font _labelFont = new Font("黑体", Font.PLAIN, 10);
	protected final static Color _background = Color.WHITE; 
	protected final static Color _fontColor = Color.GRAY;
	protected final static StandardPieSectionLabelGenerator _labelGenerator = new StandardPieSectionLabelGenerator(
			"{1},{2}");

	// protected final static StandardPieSectionLabelGenerator
	// _legendLabelGenerator = new StandardPieSectionLabelGenerator(
	// "Tooltip for legend item {0}");
	protected final TextTitle _title = new TextTitle("", _titleFont);
	protected JFreeChart _chart = null;

	/** initialise the chart with special style */
	protected void initChart(JFreeChart chart) {
		if (chart != null) {
			chart.setTitle(_title);
			chart.setBorderVisible(false);
			chart.setBackgroundPaint(_background);

			LegendTitle legend = chart.getLegend();
			if (legend != null) {
				legend.setItemFont(_labelFont);
				legend.setBackgroundPaint(_background);
			}

			initPlot(chart.getPlot());

			if (logger.isDebugEnabled()) {
				logger.debug("initializing chart generator completed.");
			}
		}
	}

	/** initialise the plot of the chart. this method must be override */
	protected abstract void initPlot(Plot plot);

}
